If you’re a regular Insider reader, you’ll know that this newsletter is all about providing insightful tips and tricks to optimize development. “5 things you didn’t know you could do with GitHub Projects.” “GitHub’s top keyboard shortcuts.”Etc, etc. But in this newsletter, we’re going something a little unconventional and present the top things NOT to do with GitHub Copilot. Call us a wild child, but we think this approach will be helpful in enabling you to take your AI-powered coding to the next level. 💪
(We’d like to thank @ReynaldAdolphe from the VS Code team for his video, Copilot Best Practices (What Not To Do), which was the inspiration for this edition!)
#1: Don’t let GitHub Copilot fly the plane ✈️
We call it GitHub Copilot for a reason. It is meant to be an assistant for you, but not to be a replacement for you, the real pilot. It doesn’t always produce correct, secure code. So, while it’s tempting to let GitHub Copilot build code for you, don’t ask it to build code on its own and assume success. The tool should point you in the right direction and help you complete the code you write, rather than write code for you. You are always the pilot, the master of the development skies!
#2: Don’t misuse GitHub Copilot tools 🙅
While there isn’t quite a “wrong way” to use GitHub Copilot, there are definitely ideal ways and suboptimal ways. It’s like eating spaghetti: you could eat it with a spoon, but you’ll have a heck of a time getting the noodles into your mouth and will probably end up with a slimy, messy floor.
Likewise, when prompting GitHub Copilot, you want to do it as effectively as possible. For example, right after line 14 below, you can use comments to prompt GitHub Copilot into adding a product rating to the form. But it’s not the most effective way to do it.
If you’re in code and want to make a prompt, use the inline chat feature! Simply hit Ctrl + I for Windows or Cmd + I for Apple.
Then, add your prompt. And voilà! It makes a suggestion on line 15 below which you can accept.
The other way to prompt is to use the side chat panel on the left, but this is more for conversational questions, rather than simple prompting. Using the above example, you can ask, “Where else in this app must I update if I add product rating to this form?” (Bonus: GitHub Copilot doesn’t care if you misspell words or have horrible grammar! A true friend. 😝)
And just like that, in the chat, GitHub Copilot will tell you all places that you need to update, easy-peasy.
Plus, if you’re not sure about what you want to add, you can always use ghost text where GitHub Copilot gives you suggestions of what you might want to include. For example, if you’re not sure you want to add product rating, you can use ghost text to understand what info you’d need and where you’d need to include it.
Remember, you always want to do the simplest thing first! Use inline chat and ghost text for basic coding, and leverage the chat panel for more detailed conversations. And don’t use comments for prompting!
#3: Don’t recreate existing prompts 🚫
Prompts are great, but don’t sleep on slash commands. If you just want to do something common, like ask GitHub Copilot to explain a code block or fix a bug, use the slash commands /fix or /explain to do what you want to do quicker and better. Simply type / to select and employ your command.
In addition to /fix and /explain, you can also use:
- /doc to add a documentation comment.
- /explain to explain the code.
- /fix to propose a fix for the problems in the selected code.
- /generate to generate code to answer your question.
- /help to get help with GitHub Copilot Chat.
- /optimize to analyze and improve the running time of the selected code.
- /tests to create unit tests for the selected code.
Sometimes, there are multiple suggestions for different commands, so make sure to navigate through each solution to find the one that’s best for you. Also, the slash commands work in the chat panel too.
#4: Don’t forget about context 🌀
If we’ve said it once, we’ve said it a thousand times: when using GitHub Copilot, context is everything. The clearer the context, the better the suggestions. This means providing the right information in the right way.
- In the chat panel, delete previous questions to make the current answers more relevant.
- Have the related parts of your code selected when asking GitHub Copilot a question.
- Use the @workspace agent–it knows about your workspace and can answer questions related to it.
- Add files to your project that GitHub Copilot takes into consideration when answering questions. Don’t be afraid to open a related tab or two in your editor as well.
- Use prompts that you’ve already asked–in the panel, use the up arrow to navigate through your previous prompts, which saves time.
#5: Don’t ignore feedback features 👍
One of the things that makes GitHub Copilot special is that it isn’t static. It gets better the more you use it and we also make improvements based on user feedback. Using the feedback and rating features of GitHub Copilot provides invaluable information back to the team, and helps make the tool better and better! Use the thumbs up and thumbs down buttons on the right hand side of each suggestion to let the team know if this info was valuable. Plus, you can report issues by clicking on the ellipsis right above.
With these tips on what to avoid, you’ll be on your way to increasing your productivity and making fantastic contributions to the development world. Go forth and code! 🔥
Other Copilot tidbits:
- VS Code Day is April 23-24, 2024 and you can tune in at YouTube.com/@code–there will be some sessions on getting the most out of Copilot and more. If you can’t join live, sessions will be archived on YouTube.
- A new, unified Copilot experience is coming to Visual Studio this May. Copilot and Copilot Chat will now live in one streamlined interface. You can check out more details on the Visual Studio blog.
- Want to know how GitHub engineers use GitHub Copilot? Holger Staudacher wrote a great blog post on how we do it.
Get started with GitHub Copilot
✨ This newsletter was written by Christina Warren and produced by Gwen Davis. ✨
More to explore 🌎
Join our GitHub Copilot conversations 🤖
Visit our community forum to see what people are saying + offer your own two cents.
Stay updated on GitHub products 📦
Discover the latest ships, launches, and improvements in our Changelog.
Subscribe to our LinkedIn newsletter 🚀
Do your best work on GitHub. Subscribe to our LinkedIn newsletter, Branching Out_.